package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.CarClassDao;
import cn.topevery.garden.entity.dto.CarClassDTO;
import cn.topevery.garden.entity.po.CarClass;
import cn.topevery.garden.entity.query.CarClassQuery;
import cn.topevery.garden.entity.vo.CarClassVO;
import cn.topevery.garden.framework.base.BaseLogic;
import com.github.dozermapper.core.Mapper;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Service
public class CarClassLogic extends BaseLogic<CarClass> {
    @Autowired
    CarClassDao carClassDao;

    @Autowired
    private Mapper mapper;

    @Override
    public BaseEntityDao<CarClass, Integer> getDao() {
        return carClassDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<CarClass> listPage(CarClassQuery query) {
        return carClassDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        carClassDao.delete(userId, ids);
    }

    public List<CarClassVO> getListByPid(String pid) {
        List<CarClass> list = carClassDao.getListByPid(pid);
        return list.stream()
                .map(temp -> mapper.map(temp, CarClassVO.class)).collect(Collectors.toList());
    }

    public void saveOrUpdate(String userId, CarClassDTO dto) {
        carClassDao.saveOrUpdate(userId, mapper.map(dto, CarClass.class));
    }

    public CarClassVO getById(Integer id) {
        return mapper.map(carClassDao.getEntity(id), CarClassVO.class);
    }

    public void delById(Integer userId, String entityId) {
        carClassDao.delByEntityId(userId, entityId);
    }
    public List<Map<String, Object>> getOptions(){
        return  carClassDao.getOptions();
    }
}
